$(function() {
	query_lens();  //光学镜架
	query_mounting(); //光学镜片
	query_sunglass(); //太阳境
	query_presbyopic(); //成品镜
	query_contactlens(); //隐形眼镜
	query_care_solution(); //护理产品
	query_other(); //其它辅料
	query_drugs(); //药品
	$('.select-all').click(function(){
		var fullCheckBoxs = $(this).parent().parent().parent().parent().parent().parent().find('tbody').find('input[type="checkbox"]');
		if($(this).prop('checked')) {
			fullCheckBoxs.prop('checked', true);
		} else {
			fullCheckBoxs.prop('checked', false);
		}
	});
});
function query_lens() {
	var data = {'entry_id':entry_id,'typeid':10};
	$.post(query_url,data,function(rtn){
		if(rtn&&rtn.data.length>0){
			var rtnhtml = appendHtml(rtn.data,'lens');
			$("#lens_datatable").find("tbody").append(rtnhtml);
			mathTotalPurchaseNum("lens_datatable");
		}else{
			$("#lens_datatable").parent().parent().hide();
		}
	},'json');
}
function query_mounting() {
	var data = {'entry_id':entry_id,'typeid':30};
	$.post(query_url,data,function(rtn){
		if(rtn&&rtn.data.length>0){
			var rtnhtml = appendHtml(rtn.data,'mounting');
			$("#mounting_datatable").find("tbody").append(rtnhtml);
			mathTotalPurchaseNum("mounting_datatable");
		}else{
			$("#mounting_datatable").parent().parent().hide();
		}
	},'json');
}
function query_sunglass() {
	var data = {'entry_id':entry_id,'typeid':41};
	$.post(query_url,data,function(rtn){
		if(rtn&&rtn.data.length>0){
			var rtnhtml = appendHtml(rtn.data,'sunglass');
			$("#sunglass_datatable").find("tbody").append(rtnhtml);
			mathTotalPurchaseNum("sunglass_datatable");
		}else{
			$("#sunglass_datatable").parent().parent().hide();
		}
	},'json');
}
function query_presbyopic() {
	var data = {'entry_id':entry_id,'typeid':40};
	$.post(query_url,data,function(rtn){
		if(rtn&&rtn.data.length>0){
			var rtnhtml = appendHtml(rtn.data,'presbyopic_glass');
			$("#presbyopic_glass_datatable").find("tbody").append(rtnhtml);
			mathTotalPurchaseNum("presbyopic_glass_datatable");
		}else{
			$("#presbyopic_glass_datatable").parent().parent().hide();
		}
	},'json');
}
function query_contactlens() {
	var data = {'entry_id':entry_id,'typeid':20};
	$.post(query_url,data,function(rtn){
		if(rtn&&rtn.data.length>0){
			var rtnhtml = appendHtml(rtn.data,'contact_lens');
			$("#contact_lens_datatable").find("tbody").append(rtnhtml);
			mathTotalPurchaseNum("contact_lens_datatable");
		}else{
			$("#contact_lens_datatable").parent().parent().hide();
		}
	},'json');
}

function query_other() {
	var data = {'entry_id':entry_id,'typeid':60};
	$.post(query_url,data,function(rtn){
		if(rtn&&rtn.data.length>0){
			var rtnhtml = appendHtml(rtn.data,'other');
			$("#other_datatable").find("tbody").append(rtnhtml);
			mathTotalPurchaseNum("other_datatable");
		}else{
			$("#other_datatable").parent().parent().hide();
		}
	},'json');
}

function query_care_solution() {
	var data = {'entry_id':entry_id,'typeid':50};
	$.post(query_url,data,function(rtn){
		if(rtn&&rtn.data.length>0){
			var rtnhtml = appendHtml(rtn.data,'contact_lens_care_solution');
			$("#contact_lens_care_solution_datatable").find("tbody").append(rtnhtml);
			mathTotalPurchaseNum("contact_lens_care_solution_datatable");
		}else{
			$("#contact_lens_care_solution_datatable").parent().parent().hide();
		}
	},'json');
}
//药品
function query_drugs() {
	var data = {'entry_id':entry_id,'typeid':70};
	$.post(query_url,data,function(rtn){
		if(rtn&&rtn.data.length>0){
			var rtnhtml = appendHtml(rtn.data,'contact_drugs');
			$("#contact_drugs_datatable").find("tbody").append(rtnhtml);
			mathTotalPurchaseNum("contact_drugs_datatable");
		}else{
			$("#contact_drugs_datatable").parent().parent().hide();
		}
	},'json');
}
function appendHtml(resultset,type){
	html=[];
	for ( var index in resultset) {
		if(type=="lens"){
			html.push('<tr rowid="'+index+'">');
			html.push('<td><div class="checkbox"><label><input type="checkbox"><i></i></label></div></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Id+'" name="id" style="display: none;" readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Products.Id+'" name="goods_id"  readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="' + resultset[index].Snd.id + '" name="snd_id" readonly="true"/></td>');
			html.push('<td td_name="goods_name">' +productGroupName(resultset[index].Products)+ '</td>');
			html.push('<td td_name="sph">'+resultset[index].Snd.sph+'</td>');
			html.push('<td td_name="cyl">'+resultset[index].Snd.cyl+'</td>');
			html.push('<td td_name="purchase_num">'+resultset[index].purchase_num+'</td>');
			html.push('<td><input type="number" name="storage_num" style="width:130px;" min="1" oninput="validAcceptNum(this,'+(resultset[index].purchase_num-resultset[index].storage_num)+')" max="'+(resultset[index].purchase_num-resultset[index].storage_num)+'" value='+(resultset[index].purchase_num-resultset[index].storage_num)+'></td>');
			html.push('<td style="text-align: center;">');
			html.push('<a class="btn-tools" href="javascript:void(0);" onclick="deleteRow(this)"><i class="am-icon-trash-o am-text-danger"></i></a>');
			html.push('</td>');
			html.push("</tr>");
		}else if(type=="mounting"){
			html.push('<tr rowid="'+index+'">');
			html.push('<td><div class="checkbox"><label><input type="checkbox"><i></i></label></div></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Id+'" name="id" style="display: none;" readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Products.Id+'" name="goods_id"  readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="' + resultset[index].Snd.id + '" name="snd_id" readonly="true"/></td>');
			html.push('<td td_name="goods_name">' +productGroupName(resultset[index].Products)+ '</td>');
			html.push('<td td_name="model">'+resultset[index].Snd.model+'</td>');
			html.push('<td td_name="color">'+resultset[index].Snd.color+'</td>');
			if(resultset[index].Snd.size){
				html.push('<td td_name="size">'+resultset[index].Snd.size+'</td>');
			}else{
				html.push('<td td_name="size"></td>');
			}
			if(resultset[index].Snd.genre){
				html.push('<td td_name="genre">'+resultset[index].Snd.genre+'</td>');
			}else{
				html.push('<td td_name="genre"></td>');
			}

			html.push('<td td_name="purchase_num">'+resultset[index].purchase_num+'</td>');
			html.push('<td><input type="number" name="storage_num" style="width:130px;" min="1" oninput="validAcceptNum(this,'+(resultset[index].purchase_num-resultset[index].storage_num)+')" max="'+(resultset[index].purchase_num-resultset[index].storage_num)+'" value='+(resultset[index].purchase_num-resultset[index].storage_num)+'></td>');
			html.push('<td style="text-align: center;">');
			html.push('<a class="btn-tools" href="javascript:void(0);" onclick="deleteRow(this)"><i class="am-icon-trash-o am-text-danger"></i></a>');
			html.push('</td>');
			html.push("</tr>");
		}else if(type=="sunglass"){
			html.push('<tr rowid="'+index+'">');
			html.push('<td><div class="checkbox"><label><input type="checkbox"><i></i></label></div></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Id+'" name="id" style="display: none;" readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Products.Id+'" name="goods_id"  readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="' + resultset[index].Snd.id + '" name="snd_id" readonly="true"/></td>');
			html.push('<td td_name="goods_name">' +productGroupName(resultset[index].Products)+ '</td>');
			html.push('<td td_name="model">'+resultset[index].Snd.model+'</td>');
			html.push('<td td_name="color">'+resultset[index].Snd.color+'</td>');
			if(resultset[index].Snd.size){
				html.push('<td td_name="size">'+resultset[index].Snd.size+'</td>');
			}else{
				html.push('<td td_name="size"></td>');
			}
			if(resultset[index].Snd.function_info){
				html.push('<td td_name="function_info">'+resultset[index].Snd.function_info+'</td>');
			}else{
				html.push('<td td_name="function_info"></td>');
			}
			if(resultset[index].Snd.film_color){
				html.push('<td td_name="film_color">'+resultset[index].Snd.film_color+'</td>');
			}else{
				html.push('<td td_name="film_color"></td>');
			}
			if(resultset[index].Snd.genre){
				html.push('<td td_name="genre">'+resultset[index].Snd.genre+'</td>');
			}else{
				html.push('<td td_name="genre"></td>');
			}
			html.push('<td td_name="purchase_num">'+resultset[index].purchase_num+'</td>');
			html.push('<td><input type="number" name="storage_num" style="width:130px;" min="1" oninput="validAcceptNum(this,'+(resultset[index].purchase_num-resultset[index].storage_num)+')" max="'+(resultset[index].purchase_num-resultset[index].storage_num)+'" value='+(resultset[index].purchase_num-resultset[index].storage_num)+'></td>');
			html.push('<td style="text-align: center;">');
			html.push('<a class="btn-tools" href="javascript:void(0);" onclick="deleteRow(this)"><i class="am-icon-trash-o am-text-danger"></i></a>');
			html.push('</td>');
			html.push("</tr>");
		}else if(type=="presbyopic_glass"){
			html.push('<tr rowid="'+index+'">');
			html.push('<td><div class="checkbox"><label><input type="checkbox"><i></i></label></div></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Id+'" name="id" style="display: none;" readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Products.Id+'" name="goods_id"  readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="' + resultset[index].Snd.id + '" name="snd_id" readonly="true"/></td>');
			html.push('<td td_name="goods_name">' +productGroupName(resultset[index].Products)+ '</td>');
			html.push('<td td_name="sph">'+resultset[index].Snd.sph+'</td>');
			html.push('<td td_name="add_info">'+resultset[index].Snd.add+'</td>');
			html.push('<td td_name="purchase_num">'+resultset[index].purchase_num+'</td>');
			html.push('<td><input type="number" name="storage_num" style="width:130px;" min="1" oninput="validAcceptNum(this,'+(resultset[index].purchase_num-resultset[index].storage_num)+')" max="'+(resultset[index].purchase_num-resultset[index].storage_num)+'" value='+(resultset[index].purchase_num-resultset[index].storage_num)+'></td>');
			html.push('<td style="text-align: center;">');
			html.push('<a class="btn-tools" href="javascript:void(0);" onclick="deleteRow(this)"><i class="am-icon-trash-o am-text-danger"></i></a>');
			html.push('</td>');
			html.push("</tr>");
		}else if(type=="contact_lens"){  //隐形眼镜
			if(!resultset[index].lot_number){
				resultset[index].lot_number="";
			}
			if(!resultset[index].manufacture_date){
				resultset[index].manufacture_date="";
			}else{
				resultset[index].manufacture_date=timetransDate(resultset[index].manufacture_date);
			}
			if(!resultset[index].expiry_date){
				resultset[index].expiry_date="";
			}else{
				resultset[index].expiry_date=timetransDate(resultset[index].expiry_date);
			}
			html.push('<tr rowid="'+index+'">');
			html.push('<td><div class="checkbox"><label><input type="checkbox"><i></i></label></div></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].entry_data_id+'" name="id" style="display: none;" readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Id+'" name="glasses_purchase_goods_detail_id" style="display: none;" readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Products.Id+'" name="goods_id"  readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="' + resultset[index].Snd.id + '" name="snd_id" readonly="true"/></td>');
			html.push('<td td_name="goods_name">'+productGroupName(resultset[index].Products)+'</td>');
			html.push('<td td_name="sph">'+resultset[index].Snd.sph+'</td>');
			html.push('<td td_name="cyl">'+resultset[index].Snd.cyl+'</td>');

			if(resultset[index].lot_number){
				html.push('<td><input name="lot_number" value="'+resultset[index].lot_number+'" readonly="readonly" style="background:#fafafa;"  type="text"></td>');
			}else{
				html.push('<td><input name="lot_number"  type="text"></td>');
			}
			if(resultset[index].manufacture_date){
				html.push('<td><input name="manufacture_date" value="'+resultset[index].manufacture_date+'" type="text" readonly="readonly" style="background:#fafafa;" ></td>');
			}else{
				html.push('<td><input  name="manufacture_date"  type="text" class="form-control date-picker" ctype="datefield" name="manufacture_date" format="yyyy-MM-dd" value="" islabel="false" isherf="false" htmlescape="false" cols="1"></td>');
			}
			if(resultset[index].expiry_date){
				html.push('<td><input name="expiry_date" type="text" value="'+resultset[index].expiry_date+'" readonly="readonly" style="background:#fafafa;"></td>');
			}else{
				html.push('<td><input name="expiry_date" type="text"  readonly="readonly" style="background:#fafafa;"></td>');
			}
			html.push('<td td_name="accept_num">'+resultset[index].accept_num+'</td>');
			html.push('<td><input type="number" name="storage_num" style="width:130px;" min="1" oninput="validAcceptNum(this,'+(resultset[index].accept_num)+')" max="'+(resultset[index].accept_num)+'" value='+(resultset[index].accept_num-resultset[index].storage_num)+'></td>');
			html.push('<td style="text-align: center;">');
			html.push('<a class="btn-tools" href="javascript:void(0);" onclick="deleteRow(this)"><i class="am-icon-trash-o am-text-danger"></i></a>');
			html.push('</td>');
			html.push("</tr>");
		}else if(type=="contact_lens_care_solution"){ //护理产品
			if(!resultset[index].lot_number){
				resultset[index].lot_number="";
			}
			if(!resultset[index].manufacture_date){
				resultset[index].manufacture_date="";
			}else{
				resultset[index].manufacture_date=timetransDate(resultset[index].manufacture_date);
			}
			if(!resultset[index].expiry_date){
				resultset[index].expiry_date="";
			}else{
				resultset[index].expiry_date=timetransDate(resultset[index].expiry_date);
			}
			html.push('<tr rowid="'+index+'">');
			html.push('<td><div class="checkbox"><label><input type="checkbox"><i></i></label></div></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].entry_data_id+'" name="id" style="display: none;" readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Id+'" name="glasses_purchase_goods_detail_id" style="display: none;" readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Products.Id+'" name="goods_id"  readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="' + resultset[index].Snd.id + '" name="snd_id" readonly="true"/></td>');
			html.push('<td td_name="goods_name">'+productGroupName(resultset[index].Products)+'</td>');
			if(resultset[index].lot_number){
				html.push('<td><input name="lot_number" value="'+resultset[index].lot_number+'" readonly="readonly" style="background:#fafafa;"  type="text"></td>');
			}else{
				html.push('<td><input name="lot_number"  type="text"></td>');
			}
			if(resultset[index].manufacture_date){
				html.push('<td><input name="manufacture_date" value="'+resultset[index].manufacture_date+'" type="text" readonly="readonly" style="background:#fafafa;" ></td>');
			}else{
				html.push('<td><input  name="manufacture_date" type="text" class="form-control date-picker" name="manufacture_date" ></td>');
			}
			if(resultset[index].expiry_date){
				html.push('<td><input name="expiry_date" type="text" value="'+resultset[index].expiry_date+'" readonly="readonly" style="background:#fafafa;"></td>');
			}else{
				html.push('<td><input name="expiry_date" type="text"  readonly="readonly" style="background:#fafafa;"></td>');
			}
			html.push('<td td_name="accept_num">'+resultset[index].accept_num+'</td>');
			html.push('<td><input type="number" name="storage_num" style="width:130px;" min="1" oninput="validAcceptNum(this,'+(resultset[index].accept_num)+')" max="'+(resultset[index].accept_num)+'" value='+(resultset[index].accept_num-resultset[index].storage_num)+'></td>');
			html.push('<td style="text-align: center;">');
			html.push('<a class="btn-tools" href="javascript:void(0);" onclick="deleteRow(this)"><i class="am-icon-trash-o am-text-danger"></i></a>');
			html.push('</td>');
			html.push("</tr>");
		}else if(type=="other"){
			html.push('<tr rowid="'+index+'">');
			html.push('<td><div class="checkbox"><label><input type="checkbox"><i></i></label></div></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Id+'" name="id" style="display: none;" readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Products.Id+'" name="goods_id"  readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="' + resultset[index].Snd.id + '" name="snd_id" readonly="true"/></td>');
			html.push('<td td_name="goods_name">'+productGroupName(resultset[index].Products)+'</td>');

			html.push('<td td_name="purchase_num">'+resultset[index].purchase_num+'</td>');
			html.push('<td><input type="number" name="storage_num" style="width:130px;" min="1" oninput="validAcceptNum(this,'+(resultset[index].purchase_num-resultset[index].storage_num)+')" max="'+(resultset[index].purchase_num-resultset[index].storage_num)+'" value='+(resultset[index].purchase_num-resultset[index].storage_num)+'></td>');
			html.push('<td style="text-align: center;">');
			html.push('<a class="btn-tools" href="javascript:void(0);" onclick="deleteRow(this)"><i class="am-icon-trash-o am-text-danger"></i></a>');
			html.push('</td>');
			html.push("</tr>");
		}else if(type=="contact_drugs"){  //药品
			if(!resultset[index].lot_number){
				resultset[index].lot_number="";
			}
			if(!resultset[index].manufacture_date){
				resultset[index].manufacture_date="";
			}else{
				resultset[index].manufacture_date=timetransDate(resultset[index].manufacture_date);
			}
			if(!resultset[index].expiry_date){
				resultset[index].expiry_date="";
			}else{
				resultset[index].expiry_date=timetransDate(resultset[index].expiry_date);
			}
			html.push('<tr rowid="'+index+'">');
			html.push('<td><div class="checkbox"><label><input type="checkbox"><i></i></label></div></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].entry_data_id+'" name="id" style="display: none;" readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Id+'" name="glasses_purchase_goods_detail_id" style="display: none;" readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="'+resultset[index].Products.Id+'" name="goods_id"  readonly="true"/></td>');
			html.push('<td style="display:none;"><input value="' + resultset[index].Snd.id + '" name="snd_id" readonly="true"/></td>');
			html.push('<td td_name="goods_name">'+productGroupName(resultset[index].Products)+'</td>');
			if(resultset[index].lot_number){
				html.push('<td><input name="lot_number" value="'+resultset[index].lot_number+'" readonly="readonly" style="background:#fafafa;"  type="text"></td>');
			}else{
				html.push('<td><input name="lot_number"  type="text"></td>');
			}
			if(resultset[index].manufacture_date){
				html.push('<td><input name="manufacture_date" value="'+resultset[index].manufacture_date+'" type="text" readonly="readonly" style="background:#fafafa;" ></td>');
			}else{
				html.push('<td><input  name="manufacture_date" type="text" class="form-control date-picker" name="manufacture_date" ></td>');
			}
			if(resultset[index].expiry_date){
				html.push('<td><input name="expiry_date" type="text" value="'+resultset[index].expiry_date+'" readonly="readonly" style="background:#fafafa;"></td>');
			}else{
				html.push('<td><input name="expiry_date" type="text"  readonly="readonly" style="background:#fafafa;"></td>');
			}
			html.push('<td td_name="accept_num">'+resultset[index].accept_num+'</td>');
			html.push('<td><input type="number" name="storage_num" style="width:130px;" min="1" oninput="validAcceptNum(this,'+(resultset[index].accept_num)+')" max="'+(resultset[index].accept_num)+'" value='+(resultset[index].accept_num-resultset[index].storage_num)+'></td>');
			html.push('<td style="text-align: center;">');
			html.push('<a class="btn-tools" href="javascript:void(0);" onclick="deleteRow(this)"><i class="am-icon-trash-o am-text-danger"></i></a>');
			html.push('</td>');
			html.push("</tr>");
		}else{
			layer.alert("未知商品类型");
			return;
		}
	}
	return html.join("");
}
function validAcceptNum(obj,storage_num){//验收数量不能填0--如果不验收改商品直接使用删除功能
	if($(obj).val()<1){
		$(obj).val(1);
	}
	if($(obj).val()>storage_num){
		$(obj).val(storage_num);
	}
	var table_name = $(obj).parents("table").attr("id");
	mathTotalPurchaseNum(table_name);
}
function deleteRow(obj){
	var table_name = $(obj).parents("table").attr("id");
	$(obj).parents("tbody").find("tr[rowid='"+$(obj).parent().parent().attr("rowid")+"']").remove();
	mathTotalPurchaseNum(table_name);
}
function mathTotalPurchaseNum(table_name){
	var total_purchase = 0
	$("#"+table_name).find("tr[rowid]").each(function(){
		total_purchase =total_purchase+parseInt($(this).find("input[name='storage_num']").val());
	});
	$("#"+table_name).parent().prev().find("div[table_type='"+table_name+"']").find("span").text("("+total_purchase+")");
}

function save(){
	var _data  = {
		entry_id:entry_id,
		datatable:[],
		datatable1:[],
		datatable2:[],
		datatable3:[],
		datatable4:[],
		datatable5:[],
		datatable6:[],
		datatable7:[],
	};
	$("#lens_datatable").find("tr[rowid]").each(function(){
		var data={};
		data.id=$(this).find("input[name='id']").val();
		data.goods_id=$(this).find("input[name='goods_id']").val();
		data.snd_id=$(this).find("input[name='snd_id']").val();
		data.goods_name=$(this).find("td[td_name='goods_name']").text();
		data.sph=$(this).find("td[td_name='sph']").text();
		data.cyl=$(this).find("td[td_name='cyl']").text();
		data.add_info=$(this).find("td[td_name='add_info']").text();
		data.pass=$(this).find("td[td_name='pass']").text();
		data.purchase_num=$(this).find("td[td_name='purchase_num']").text();
		data.storage_num=$(this).find("input[name='storage_num']").val();
		_data.datatable.push(data);
	});

	$("#mounting_datatable").find("tr[rowid]").each(function(){
		var data={};
		data.id=$(this).find("input[name='id']").val();
		data.goods_id=$(this).find("input[name='goods_id']").val();
		data.snd_id=$(this).find("input[name='snd_id']").val();
		data.goods_name=$(this).find("td[td_name='goods_name']").text();
		data.model=$(this).find("td[td_name='model']").text();
		data.color=$(this).find("td[td_name='color']").text();
		data.size=$(this).find("td[td_name='size']").text();
		data.genre=$(this).find("td[td_name='genre']").text();//默认一个框型参数
		data.purchase_num=$(this).find("td[td_name='purchase_num']").text();
		data.storage_num=$(this).find("input[name='storage_num']").val();
		_data.datatable1.push(data);
	});

	$("#sunglass_datatable").find("tr[rowid]").each(function(){
		var data={};
		data.id=$(this).find("input[name='id']").val();
		data.goods_id=$(this).find("input[name='goods_id']").val();
		data.snd_id=$(this).find("input[name='snd_id']").val();
		data.goods_name=$(this).find("td[td_name='goods_name']").text();
		data.model=$(this).find("td[td_name='model']").text();
		data.color=$(this).find("td[td_name='color']").text();
		data.size=$(this).find("td[td_name='size']").text();
		data.function_info=$(this).find("td[td_name='function_info']").text();//默认一个功效参数

		data.film_color=$(this).find("td[td_name='film_color']").text();
		data.genre=$(this).find("td[td_name='genre']").text()//默认一个框型参数
		data.purchase_num=$(this).find("td[td_name='purchase_num']").text();
		data.storage_num=$(this).find("input[name='storage_num']").val();
		_data.datatable2.push(data);
	});

	$("#presbyopic_glass_datatable").find("tr[rowid]").each(function(){
		var data={};
		data.id=$(this).find("input[name='id']").val();
		data.goods_id=$(this).find("input[name='goods_id']").val();
		data.snd_id=$(this).find("input[name='snd_id']").val();
		data.goods_name=$(this).find("td[td_name='goods_name']").text();
		data.sph=$(this).find("td[td_name='sph']").text();
		data.add_info=$(this).find("td[td_name='add_info']").text();
		data.purchase_num=$(this).find("td[td_name='purchase_num']").text();
		data.storage_num=$(this).find("input[name='storage_num']").val();
		_data.datatable3.push(data);
	});

	$("#contact_lens_datatable").find("tr[rowid]").each(function(){
		var data={};
		data.id=$(this).find("input[name='id']").val();
		data.glasses_purchase_goods_detail_id=$(this).find("input[name='glasses_purchase_goods_detail_id']").val();
		data.goods_id=$(this).find("input[name='goods_id']").val();
		data.snd_id=$(this).find("input[name='snd_id']").val();
		data.goods_custom_id=$(this).find("input[name='goods_custom_id']").val();
		data.goods_name=$(this).find("td[td_name='goods_name']").text();
		data.sph=$(this).find("td[td_name='sph']").text();
		data.cyl=$(this).find("td[td_name='cyl']").text();
		data.lot_number=$(this).find("input[name='lot_number']").val();
		data.manufacture_date=$(this).find("input[name='manufacture_date']").val();
		data.expiry_date=$(this).find("input[name='expiry_date']").val();
		data.purchase_num=$(this).find("td[td_name='purchase_num']").text();
		data.accept_num=$(this).find("td[td_name='accept_num']").text();
		data.storage_num=$(this).find("input[name='storage_num']").val();
		_data.datatable4.push(data);
	});
	$("#contact_lens_care_solution_datatable").find("tr[rowid]").each(function(){
		var data={};
		data.id=$(this).find("input[name='id']").val();
		data.glasses_purchase_goods_detail_id=$(this).find("input[name='glasses_purchase_goods_detail_id']").val();
		data.goods_id=$(this).find("input[name='goods_id']").val();
		data.goods_name=$(this).find("td[td_name='goods_name']").text();
		data.lot_number=$(this).find("input[name='lot_number']").val();
		data.manufacture_date=$(this).find("input[name='manufacture_date']").val();
		data.expiry_date=$(this).find("input[name='expiry_date']").val();
		data.purchase_num=$(this).find("td[td_name='purchase_num']").text();
		data.accept_num=$(this).find("td[td_name='accept_num']").text();
		data.storage_num=$(this).find("input[name='storage_num']").val();
		_data.datatable5.push(data);
	});
	$("#other_datatable").find("tr[rowid]").each(function(){
		var data={};
		data.id=$(this).find("input[name='id']").val();
		data.goods_id=$(this).find("input[name='goods_id']").val();
		data.goods_name=$(this).find("td[td_name='goods_name']").text();
		data.purchase_num=$(this).find("td[td_name='purchase_num']").text();
		data.storage_num=$(this).find("input[name='storage_num']").val();
		_data.datatable6.push(data);
	});
	$("#contact_drugs_datatable").find("tr[rowid]").each(function(){
		var data={};
		data.id=$(this).find("input[name='id']").val();
		data.glasses_purchase_goods_detail_id=$(this).find("input[name='glasses_purchase_goods_detail_id']").val();
		data.goods_id=$(this).find("input[name='goods_id']").val();
		data.goods_name=$(this).find("td[td_name='goods_name']").text();
		data.lot_number=$(this).find("input[name='lot_number']").val();
		data.manufacture_date=$(this).find("input[name='manufacture_date']").val();
		data.expiry_date=$(this).find("input[name='expiry_date']").val();
		data.purchase_num=$(this).find("td[td_name='purchase_num']").text();
		data.accept_num=$(this).find("td[td_name='accept_num']").text();
		data.storage_num=$(this).find("input[name='storage_num']").val();
		_data.datatable7.push(data);
	});
	for(var index in _data.datatable1){
		if(!_data.datatable1[index].genre){
			layer.alert("光学镜架框型参数不全");
			return;
		}
	}
	for(var index in _data.datatable2){
		if(!_data.datatable2[index].genre){
			layer.alert("太阳镜框型参数不全");
			return;
		}
	}
	if(_data.datatable.length<=0&&
			_data.datatable1.length<=0&&
			_data.datatable2.length<=0&&
			_data.datatable3.length<=0&&
			_data.datatable4.length<=0&&
			_data.datatable5.length<=0&&
			_data.datatable6.length<=0&&
			_data.datatable7.length<=0){
		layer.alert("未找到入库商品");
		return;
	}
	_data.datatable = JSON.stringify(_data.datatable);
	_data.datatable1 = JSON.stringify(_data.datatable1);
	_data.datatable2 = JSON.stringify(_data.datatable2);
	_data.datatable3 = JSON.stringify(_data.datatable3);
	_data.datatable4 = JSON.stringify(_data.datatable4);
	_data.datatable5 = JSON.stringify(_data.datatable5);
	_data.datatable6 = JSON.stringify(_data.datatable6);
	_data.datatable7 = JSON.stringify(_data.datatable7);
	layer.confirm("确认入库信息无误？", function(c) {
		if (c) {
			var thindex = layer.load();
			$.post(save_url,_data,function(rtn){
				layer.close(thindex);
				if(rtn.code == 1) {
					layer.alert(rtn.msg);
					return false;
				}
				layer.alert("入库成功",function(){
					history.back();
				});
			},'json');
		}
	});

}
